package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.ServiceMapper;
import com.situ.springboot.pojo.entity.User;
import com.situ.springboot.service.ServiceService;
import com.situ.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServiceServiceImpl implements ServiceService {

    @Autowired
    private ServiceMapper serviceMapper;

    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {
        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前也数据
        List<com.situ.springboot.pojo.entity.Service> list = serviceMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = serviceMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<>(list, totalPage, pageNo, pageSize);
    }




    @Override
    public com.situ.springboot.pojo.entity.Service selectById(Integer id) {
        return serviceMapper.selectById(id);
    }

    @Override
    public void update(com.situ.springboot.pojo.entity.Service service) {
        serviceMapper.update(service);
    }

    @Override
    public void add(com.situ.springboot.pojo.entity.Service service) {
        serviceMapper.add(service);
    }


    @Override
    public void deleteById(Integer id) {
        serviceMapper.deleteById(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        serviceMapper.deleteAll(ids);
    }

    @Override
    public List<com.situ.springboot.pojo.entity.Service> selectAll() {
        return serviceMapper.selectAll();
    }

    @Override
    public List<com.situ.springboot.pojo.entity.Service> selectByContent(String content) {
        return serviceMapper.selectByContent(content);
    }
}
